package com.chebaohui.iqs.service.impl;

import org.springframework.stereotype.Service;

import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;
import com.chebaohui.iqs.config.ResultCode;
import com.chebaohui.iqs.entity.Paramter;
import com.chebaohui.iqs.entity.Result;
import com.chebaohui.iqs.entity.req.LastYearPolicyReq;
import com.chebaohui.iqs.entity.res.LastYearPolicyRes;
import com.chebaohui.iqs.service.CheckService;
import com.chebaohui.iqs.service.impl.deal.bihu.profess.BiHuPolicyCheck;
import com.chebaohui.iqs.service.impl.deal.util.CompanyUtil;
import com.chebaohui.iqs.service.impl.deal.util.StringUtil;

@Service
public class CheckServiceImpl implements CheckService {
	
	/**
	 * log:日志输出
	 */
	private Log log = LogFactory.getLog(CheckServiceImpl.class);

	@Override
	public Result<LastYearPolicyRes> lastPolicy(Paramter<LastYearPolicyReq> param) {
		try {
			//1判断必传值车牌号 
			if(!CompanyUtil.valLicenceNo(param.getData().getLicenceNo()))
				return new Result<LastYearPolicyRes>(ResultCode.N02, "车牌号格式错误:" + param.getData().getLicenceNo());
			
			if(!StringUtil.isNulls(param.getData().getFrameNo()) && !CompanyUtil.valFrameNo(param.getData().getFrameNo()))
				return new Result<LastYearPolicyRes>(ResultCode.N02, "车架号格式错误:" + param.getData().getFrameNo());
			
			if(!StringUtil.isNulls(param.getData().getEngineNo()) && !CompanyUtil.valEngineNo(param.getData().getEngineNo()))
				return new Result<LastYearPolicyRes>(ResultCode.N02, "发动机号格式错误:" + param.getData().getEngineNo());
			
			return new BiHuPolicyCheck().policy(param.getData());
		} catch (Exception e) {
			log.error("《壁虎接口1》往年保单信息获取异常"+e.getMessage());
			return new Result<LastYearPolicyRes>(ResultCode.N02, "policy查询异常:" + e.getMessage());
		}
	}
}
